package com.ruiysoft.conf.logistics;

import com.ruiysoft.service.logistics.ExpressCollerFactory;
import com.ruiysoft.service.logistics.Kuaidi100Caller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import javax.annotation.PostConstruct;
import java.util.Arrays;

@Configuration
public class LogisticsConfig {

    private  static final  String BEAN_REST_TEMPLATE_FOR_THIRD_KUAIDI100 = "RestTemplate_For_Third_KUAIDI100";

    @Value("${logistics.baseCallBackURL}")
    private String baseCallBackUrl = "https://xcx.ruiysoft.com/microshop/devapi";

    /*@Autowired
    private ILogisticsCompanyBaseService iLogisticsCompanyBaseService;

    @Autowired
    private ILogisticsShopApiConfService iLogisticsShopApiConfService;

    @Autowired
    private LogisticsShopApiConfMapper logisticsShopApiConfMapper;*/

    @Bean
    Kuaidi100Caller getKuaidi100Caller(){
        return new Kuaidi100Caller(baseCallBackUrl);
    }

    @PostConstruct
    public void initExpressCollerFactory(){
        ExpressCollerFactory
                /*.initFactory(
                        iLogisticsCompanyBaseService,
                        iLogisticsShopApiConfService,
                        logisticsShopApiConfMapper)*/
                .getInstance()
                .registerColler(Arrays.asList(getKuaidi100Caller()));
    }

    @Bean(name = BEAN_REST_TEMPLATE_FOR_THIRD_KUAIDI100)
    RestTemplate kuaid100RestTemplate() {
        return new RestTemplate();
    }
}
